package com.midian.action.mc.organization;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.midian.action.mc.common.AjaxAction;
import com.midian.common.annotation.FileModelDetails;
import com.midian.common.annotation.FunctionAnnotationOverride;
import com.midian.common.exception.BizException;
import com.midian.common.utils.PicUtils;
import com.midian.model.common.FileModel;
import com.midian.model.organization.Organization;
import com.midian.model.organization.OrganizationType;
import com.midian.model.pic.Pic;
import com.midian.service.organization.IOrganizationService;
import com.midian.service.organization.IOrganizationTypeService;
import com.midian.service.pic.IPicService;
import com.mysql.jdbc.log.Log;

/**
 * 机构Action
 * 
 * @author Mengfh
 *
 */
@Scope("prototype")
@Controller("organizationAction")
@FunctionAnnotationOverride(isAction = true, auth = "机构管理")
public class OrganizationAction extends AjaxAction<Organization> {
	/** 机构实体 */
	private Organization entity;
	/** 机构实体列表 */
	private List<Organization> rows;
	/** 机构业务 */
	private IOrganizationService organizationService;
	/**机构logo*/
	private FileModel logo;
	/**机构类型列*/
	private List<OrganizationType> orgTypeList;
	/**机构类型业务*/
	private IOrganizationTypeService OrganizationTypeService;
	/**图片业务*/
	private IPicService picService;
	
	@Resource(name="organizationTypeService")
	public void setOrganizationTypeService(IOrganizationTypeService organizationTypeService) {
		OrganizationTypeService = organizationTypeService;
	}

	@Resource(name="picService")
	public void setPicService(IPicService picService) {
		this.picService = picService;
	}

	public Organization getEntity() {
		return entity;
	}
	@FileModelDetails(fieldName = "logo.id",isDelOldFile = false)
	public FileModel getLogo() {
		return logo;
	}

	public void setLogo(FileModel logo) {
		this.logo = logo;
	}

	public List<OrganizationType> getOrgTypeList() {
		return orgTypeList;
	}

	public void setOrgTypeList(List<OrganizationType> orgTypeList) {
		this.orgTypeList = orgTypeList;
	}

	public void setEntity(Organization entity) {
		this.entity = entity;
	}

	@Resource(name = "organizationService")
	public void setOrganizationService(IOrganizationService organizationService) {
		this.service = organizationService;
		this.organizationService = organizationService;
	}

	@Override
	protected Organization dytEntity() {
		if (this.entity == null) {
			this.entity = new Organization();
		}
		return getEntity();
	}

	@Override
	protected void dyEntity(Organization t) {
		setEntity(t);
	}

	@Override
	public void setRows(List<Organization> rows) {
		this.rows = rows;
	}

	@Override
	public List<Organization> getRows() {
		return rows;
	}
	
	@Override
	public String ajax() {
		try {
			orgTypeList = this.OrganizationTypeService.geOrganizationTypes();
		} catch (BizException e) {
			e.printStackTrace();
		}
		return super.ajax();
	}
	
	
	
	@Override
	public String showInfo() {
		try {
			orgTypeList = this.OrganizationTypeService.geOrganizationTypes();
		} catch (BizException e) {
			e.printStackTrace();
		}
		return super.showInfo();
	}
	
}
